# -*- coding:utf-8 -*-
import logging
from logging.handlers import RotatingFileHandler
from app.settings import Settings
from flask.logging import default_handler


def init_log(app):
    app.logger.removeHandler(default_handler)

    logging.basicConfig(
        level=Settings.LOGGING_LEVEL,
    )
    file_log_handler = RotatingFileHandler(
        Settings.LOGGING_FILE_DIR,
        Settings.LOGGING_FILE_MAX_BYTES,
        Settings.LOGGING_FILE_BACKUP,
        encoding='UTF-8',
    )
    formatter = logging.Formatter(Settings.LOGGING_FORMATTER)
    file_log_handler.setFormatter(formatter)
    logging.getLogger().addHandler(file_log_handler)
